package cn.yexiaofeng.bookmanager.controller;


import cn.yexiaofeng.bookmanager.beans.Reader_info;
import cn.yexiaofeng.bookmanager.service.ReaderInfoService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletRequest;
import java.util.List;

/**
 * 读者
 */
@Controller
public class ReaderController {

    @Autowired
    ReaderInfoService readerInfoService;


    @GetMapping(value = "/getReaderInfo")
    public String getReaderInfo(ServletRequest request) {
        String curr = request.getParameter("curr");
        String pageSize = request.getParameter("pageSize");
        if (curr == null || curr == "") {
            curr = "1";
        }
        if (pageSize == null || pageSize == "") {
            pageSize = "3";
        }
        List<Reader_info> allReaderInfo = readerInfoService.getAllReaderInfo(curr, pageSize);
        PageInfo pageInfo = new PageInfo(allReaderInfo, 3);//页面数
        request.setAttribute("allReaders", pageInfo);
        return "readers";
    }


}